package com.example.mini_notepad.activity;

import java.util.HashMap;
import java.util.List;

import com.example.mini_notepad.R;
import com.example.mini_notepad.db.NoteDBAdapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class SavedNoteFragment extends Fragment {
	ListView listView;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState){
		View rootView = inflater.inflate(R.layout.saved_note_fragment, container, false);
		listView = (ListView) rootView.findViewById(R.id.note_list);
		NoteDBAdapter db = new NoteDBAdapter(this.getActivity());
		db.open();
		List<HashMap<String, Object>> notesList = db.getAllNotesForDisplay();
		SimpleAdapter noteAdapter = new SimpleAdapter(this.getActivity(), notesList, 
				R.layout.note_item, new String[]{"note_img", "sub_content", "tv_notify_time"}, 
				new int[]{R.id.note_img, R.id.sub_content, R.id.tv_notify_time});
		listView.setAdapter(noteAdapter);
		return rootView;		
	}

}
